﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DiveManager
{
    public partial class KundensucheEinfach : Form
    {
        protected DiveDatabaseEntities diveDatabase;
        protected BindingSource bindingSource;

        public int kdnr;
        
        public KundensucheEinfach()
        {
            InitializeComponent();

            // Init Database
            diveDatabase = new DiveDatabaseEntities();
            bindingSource = new BindingSource();
        }

        private void btExit_Click(object sender, EventArgs e)
        {
            //Form schließen
            Close();
        }

        private void KundensucheEinfach_Load(object sender, EventArgs e)
        {
            LoadData();
            
            txShowKDNR.DataBindings.Add(new Binding("Text", bindingSource, "KDNR"));
        }

        protected void LoadData()
        {
            IQueryable<Customer_Main> dataQuery = (from a in diveDatabase.Customer_Main
                                                  select a);

            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;

            // Bind BindingSource to List
            CustomerList.DataSource = bindingSource;


            // Hide ID-Columns
            CustomerList.Columns["ID"].Visible = false;
            CustomerList.Columns["KDNR"].Visible = true;
            CustomerList.Columns["Anrede"].Visible = true;
            CustomerList.Columns["Titel"].Visible = true;
            CustomerList.Columns["Firma"].Visible = true;
            CustomerList.Columns["Name"].Visible = true;
            CustomerList.Columns["Vorname"].Visible = true;


            // Set Column Headers
            //CustomerList.Columns["Artikel_Nr"].HeaderText = "Art. Nr";
            //CustomerList.Columns["Name"].HeaderText = "Bezeichnung";


        }

        private void btOK_Click(object sender, EventArgs e)
        {
            //KDNR aus txShowKDNR auslesen und in kdnr speichern
            kdnr = Convert.ToInt32(txShowKDNR.Text);

            //Form schließen
            Close();
        }
    }
}
